package com.css.fxfzdpzs.modules.fwss.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzdpzs.base.response.RestResponse;
import com.css.fxfzdpzs.modules.fwss.entity.first.Fw5yearsNum;
import com.css.fxfzdpzs.modules.fwss.entity.first.FwMapDate;
import com.css.fxfzdpzs.modules.fwss.entity.second.CollectionSituation;
import com.css.fxfzdpzs.modules.fwss.entity.second.FwSiftCoverage;
import com.css.fxfzdpzs.modules.fwss.entity.second.GeneralSurveyStatistics;
import com.css.fxfzdpzs.modules.fwss.entity.second.HousingStatistics;
import com.css.fxfzdpzs.modules.fwss.vo.*;
import com.css.fxfzdpzs.modules.fwss.service.FwssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author y1fan
 * @description
 */
@RestController
@RequestMapping("/fwss")
@Slf4j
public class FwssController {

    @Resource
    private FwssService fwssService;


    /**
     * 全国房屋设施 （一级目录）1.1.1房屋设施数据采集系统情况
     * fw_collection_system_situation
     *
     * @return
     */
    @GetMapping("/getSystemSituation")
    public RestResponse getSystemSituation() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            FwCollectionSystemSituationVO fwCollectionSystemSituationVO = fwssService.getSystemSituation();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(fwCollectionSystemSituationVO);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 全国房屋设施 （一级目录）全国房屋详查数据覆盖情况
     * FwNationwideSamplingRate
     *
     * @return
     */
    @GetMapping("/getSamplingRate")
    public RestResponse getSamplingRate() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            FwProvinceSamplingRateVO fwProvinceSamplingRateVO = fwssService.getSamplingRate();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(fwProvinceSamplingRateVO);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 全国房屋设施 （一级目录）1.1.2.2各省已提交普查数据统计
     * fw_province_sampling_rate
     *
     * @return
     */
    @GetMapping("/getProvinceSamplingRate")
    public RestResponse getProvinceSamplingRate() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            FwProvinceDongAndAreaVO vo = fwssService.getProvinceSamplingRate();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(vo);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /**
     * 普查采集入库情况
     * fw_general_library_situation
     *
     * @return
     */
    @GetMapping("/getGeneralSituation")
    public RestResponse getGeneralSituation() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            GeneralSituationVO vo = fwssService.getGeneralSituation();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(vo);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /**
     * 详查采集入库情况
     * fw_sift_library_situation
     *
     * @return
     */
    @GetMapping("/getSiftSituation")
    public RestResponse getSiftSituation() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            SiftSituationVO vo = fwssService.getSiftSituation();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(vo);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /**
     * 1）表名（中文名）：近五年详查普查采集栋数  （房屋数据采集情况）
     * 表名（英文名）：fw_5years_num
     *
     * @return
     */
    @GetMapping("/getYearsNum")
    public RestResponse getYearsNum() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<Fw5yearsNum> list = fwssService.getYearsNum();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //****************二级页面***************
    //房屋抽样详查建筑结构类型统计
    @GetMapping("/getStatistics")
    public RestResponse getStatistics() {
        RestResponse restResponse = null;
        try {
            List<HousingStatistics> list = fwssService.getStatistics();
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国建筑物采集情况统计
    @GetMapping("/getSituation")
    public RestResponse getSituation() {
        RestResponse restResponse = null;
        try {
            List<CollectionSituation> list = fwssService.getSituation();
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国建筑物采集情况统计
    @GetMapping("/getGeneralSurvey")
    public RestResponse getGeneralSurvey(@RequestParam String mark) {
        RestResponse restResponse = null;
        try {
            Map<String, List<GeneralSurveyStatistics>> map = fwssService.getGeneralSurvey(mark);
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    //各省(直辖市)详查数据面积抽样率
    @GetMapping("/getSiftCoverage")
    public RestResponse getSiftCoverage() {
        RestResponse restResponse = null;
        try {
            FwSiftCoverageVO vo = fwssService.getSiftCoverage();
            restResponse = RestResponse.succeed(vo);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }



    //地图数据来源接口  房屋设施数据 普查 详查
    @GetMapping("/getMapDate")
    public RestResponse getMapDate(String flag) {
        RestResponse restResponse = null;
        try {
            List<FwMapDate> list= fwssService.getMapDate(flag);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }





}
